using Nextem.String;

namespace Renraku.Compiler {
	public variant SSAArg {
		| Id {
			Num : int
		}
		| Phi {
			Join : list [Id]
		}
		| Arg {
			Num : int
		}
		| VInt {
			Val : int
		}
		| VUInt {
			Val : uint
		}
		| VShort {
			Val : short
		}
		| VUShort {
			Val : ushort
		}
		
		public override ToString() : string {
			match(this) {
				| Id(num)        => "id({0})" <- num
				| Phi(join)      => "phi{1}" <- join
				| Arg(num)       => "arg({0})" <- num
				| VInt(val)      => "{0}" <- val
				| VUInt(val)     => "{0}" <- val
				| VShort(val)    => "{0}" <- val
				| VUShort(val)   => "{0}" <- val
			}
		}
	}
	
	public type SSABody = GraphBody [SSAArg];
	
	public module SSA {
		public FromCILGraph(cil : Assembly [CILGraphBody]) : Assembly [SSABody] {
			cil.MapMethods(SSAize)
		}
		
		SSAize(cil : CILGraphBody) : SSABody {
			print cil;
			null
		}
	}
}
